<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/**
 * Description of settings_model
 *
 * @author souzadavi
 */
class Settings_model extends CI_Model {

    //put your code here

    public function __construct() {
        parent::__construct();
    }

    public function get_categoria_join_configuracao() {
        $this->db->select('CO.*, CC.nome AS CC_nome, CC.status AS CC_status, CC.ordem AS CC_ordem ');
        $this->db->where('CC.status', 1);
        $this->db->where('CO.users_id', $this->tank_auth->get_user_id());
        $this->db->order_by("CC.ordem", "ASC");
        $this->db->order_by("CO.ordem", "ASC");
        $this->db->join('cliente_db.configuracao AS CO', 'CO.id_cat = CC.id_cat', 'INNER');
        $query = $this->db->get('cliente_db.configuracao_categoria AS CC');
        //pre($this->db->last_query());
        if ($query->num_rows() > 0) {
            return $query->result();
        } else {
            return null;
        }
    }

    public function update_configuracao($dados = array()) {
        //id, users_id, id_cat, ordem, nome, subtitulo, valor, tipo, data
        if (!is_array($dados)) {
            return NULL;
        } else {
            foreach ($dados['c_input'] as $k => $v) {
                $array = array();
                $array['valor'] = $v;
                $array['tipo'] = $dados['tipo'][$k];
                $this->db->update('cliente_db.configuracao', $array, array('id' => $k));
            }
            return TRUE;
        }
    }

}

?>
